package TestCases;

import java.awt.Point;

import junit.framework.TestCase;
import Tracer.RTBitmap;
import Tracer.RTColor;

/**
 * @author Hongyi Zhao This is the Test Case for class RTBitmap
 */
public class RTBitmapTest extends TestCase {
	private RTBitmap bitmapFromPPMBinary;
	private RTBitmap bitmapFromPPMASCII;
	RTColor colorToSet = new RTColor(177, 177, 177);

	/**
	 * @param name
	 */
	public RTBitmapTest(String name) {
		super(name);
	}

	protected void setUp() throws Exception {
		super.setUp();
		/**
		 * Read binary PPM from file.
		 */
		bitmapFromPPMBinary = new RTBitmap();
		bitmapFromPPMBinary.readFromPPM("earthmap.ppm");
		bitmapFromPPMASCII = new RTBitmap();
		bitmapFromPPMASCII.readFromPPM("earthmap-asc.ppm");

		/**
		 * Write out bitmap to PPM on disk.
		 * 
		 */
		bitmapFromPPMBinary.writeBitmapToBinaryPPM("OutputPPMBinary.ppm");
		bitmapFromPPMASCII.writeBitmapToASCIIPPM("OutputPPMASCII.ppm");
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		bitmapFromPPMBinary = null;
		bitmapFromPPMASCII = null;
	}

	/**
	 * Test method for setColorAtPoint Test it works well after performing
	 * setColorAtPoint
	 */
	public final void testSetColorAtPoint() {
		/**
		 * Set color of a specific point.
		 */
		bitmapFromPPMBinary.setColorAtPoint(new Point(0, 0), colorToSet);

		assertEquals("Setted color is incorrect", true, colorToSet
				.isEqual(bitmapFromPPMBinary.getColorAtPoint(new Point(0, 0))));
	}

	/**
	 * Test method for readFromPPM Test it works well after performing
	 * readFromPPM
	 */
	public final void testReadFromPPM() {
		assertEquals("Height from PPM binary incorrect", 319,
				bitmapFromPPMBinary.height());
		assertEquals("Width from PPM binary incorrect", 640,
				bitmapFromPPMBinary.width());

		assertEquals("Height from PPM ASCII incorrect", 319, bitmapFromPPMASCII
				.height());
		assertEquals("Width from PPM ASCII incorrect", 640, bitmapFromPPMASCII
				.width());
	}

	/**
	 * Test method for writeBitmapToBinaryPPM Test it works well after
	 * performing writeBitmapToBinaryPPM
	 */
	public final void testWriteBitmapToBinaryPPM() {
		RTBitmap bitmap = new RTBitmap();
		bitmap.readFromPPM("OutputPPMBinary.ppm");
		assertEquals("Height of output PPM binary incorrect", 319, bitmap
				.height());
		assertEquals("Width of output PPM binary incorrect", 640, bitmap
				.width());
	}

	/**
	 * Test method for writeBitmapToASCIIPPM Test it works well after performing
	 * writeBitmapToASCIIPPM
	 */
	public final void testWriteBitmapToASCIIPPM() {
		RTBitmap bitmap = new RTBitmap();
		bitmap.readFromPPM("OutputPPMASCII.ppm");
		assertEquals("Height of output PPM ASCII incorrect", 319, bitmap
				.height());
		assertEquals("Width of output PPM ASCII incorrect", 640, bitmap.width());
	}
}
